package co.fitstart.admin.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.entity.courseware.movement.Movement;

/**
 * 
 * @author Wy
 *
 */
@Repository("actionDaoSupport")
public class MovementDaoSupport {
	
	 @Autowired
	 private GenericDaoSupport genericDaoSupport;
	 
	 
	 /**
	  * search by categoryId equipmentId name
	  * 
	  * @param categoryId
	  * @param equipmentId
	  * @param name
	  * @return
	  */
	 @SuppressWarnings("unchecked")
	public List<Movement> search(Long categoryId, Long equipmentId, String name){
		 
		 String sentence = "FROM Movement movement WHERE movement.disabled = false";
		 
		 Map<String, Object> parameters = new HashMap<String, Object>();
		 
		 if(categoryId != null) {
	            parameters.put("categoryId", categoryId);
	            sentence = sentence + " AND movement.category.id = :categoryId";
	        }
		 
		 if(equipmentId != null) {
	            parameters.put("equipmentId", equipmentId);
	            sentence = sentence + " AND movement.equipment.id = :equipmentId";
	        }
		 if(name!=null){
			 
			 parameters.put("name", name);
			 sentence = sentence + " AND movement.name = :name" ;

		 }
		 
		 
		 
		return genericDaoSupport.searchForList(sentence, parameters);
		 
	 }
	 
	 
	 

}
